#include <shlobj.h>
#include"elib/fnshare.h"
namespace elibshell {
	/*BOOL ShellCopyFile(const std::string_view& DestDir, const std::string_view& SourceFile) {
		BOOL ret = FALSE;
		if (!DestDir.empty() && !SourceFile.empty()) {
			std::string Filename(SourceFile);
			std::string Dest(DestDir);
			Filename += '\0';
			Dest += '\0';
			SHFILEOPSTRUCTA FileOp = { 0 };
			FileOp.wFunc = FO_COPY;
			FileOp.fFlags = FOF_ALLOWUNDO;
			FileOp.pFrom = Filename.c_str();
			FileOp.pTo = Dest.c_str();
			if (!::SHFileOperationA(&FileOp) && !FileOp.fAnyOperationsAborted) {
				ret = TRUE;
			}
		}
		return ret;
	}
	BOOL ShellCopyFiles(const std::string_view& DestDir, const std::vector<std::string_view>& SourceFiles) {
		BOOL ret = TRUE;
		for (const auto& SourceFile : SourceFiles) {
			MessageBoxA(0, SourceFile.data(), 0, 0);
			if (!ShellCopyFile(DestDir, SourceFile)) {
				ret = FALSE;
				break;
			}
		}
		return ret;
	}*/
	BOOL ShellCopyFiles(const std::string_view& DestDir, const std::vector<std::string_view>& SourceFiles)
	{
		BOOL ret = FALSE;
		if (!DestDir.empty() && !SourceFiles.empty()) {
			std::string Dest(DestDir);
			Dest += '\0';
			SHFILEOPSTRUCTA FileOp = { 0 };
			FileOp.wFunc = FO_COPY;
			FileOp.fFlags = FOF_ALLOWUNDO;
			std::vector<char> FilenameBuffer;
			for (const auto& SourceFile : SourceFiles) {
				FilenameBuffer.resize(FilenameBuffer.size() + SourceFile.size() + 1);
				std::memcpy(FilenameBuffer.data() + FilenameBuffer.size() - SourceFile.size() - 1, SourceFile.data(), SourceFile.size());
				FilenameBuffer.back() = '\0';
			}
			FilenameBuffer.push_back('\0');
			FileOp.pFrom = FilenameBuffer.data();
			FileOp.pTo = Dest.c_str();
			if (!::SHFileOperationA(&FileOp) && !FileOp.fAnyOperationsAborted)
				ret = TRUE;
		}
		return ret;
	}

}